//
//  UnderLineTextField.m
//  SodiumSupplementCalculation
//
//  Created by Apple on 2018/12/14.
//  Copyright © 2018 lichang. All rights reserved.
//

#import "UnderLineTextField.h"

@implementation UnderLineTextField

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (id)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super initWithCoder:aDecoder]) {
        _lineHeight = 1;
        _lineColor = [UIColor lightGrayColor];
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        _lineHeight = 1;
        _lineColor = [UIColor lightGrayColor];
    }
    return self;
}

- (void)setLineColor:(UIColor *)lineColor{
    _lineColor = lineColor;
    
    [self setNeedsDisplay];
}

- (void)setLineHeight:(CGFloat)lineHeight{
    _lineHeight = lineHeight;
    
    [self setNeedsDisplay];
}


- (void)drawRect:(CGRect)rect{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, self.lineColor.CGColor);
    CGRect lineRect = CGRectMake(0, CGRectGetHeight(self.frame) - self.lineHeight-1,  CGRectGetWidth(self.frame), self.lineHeight);
    CGContextFillRect(context, lineRect);
    
}

@end
